package com.itheima.d1_method;

import java.util.Arrays;
import java.util.Random;

public class Test14 {

    public static void main(String[] args) {
//        需求1：方法需要接收一个整数数组，并返回此数组的最大值
        int[] b = {10, 22, 3, 41, 5};
        int cc = cc(b);
        System.out.println(cc);


        int[] b1 = {7, 53, 9, 22, 3};
        int[] num = cc1(b1);
        System.out.println(num[0]);

        int[] aa = cc2();
        for (int i = 0; i < aa.length; i++) {
            System.out.println(aa[i]);
        }


    }

    public static int cc(int[] a) {
//        if (a == null || a.length == 0) {
//            return;
//        }
        int max = a[0];
        for (int i = 0; i < a.length - 1; i++) {
            if (a[i] > max) {
                max = a[i];
            }
        }
        return max;
    }


    public static int[] cc1(int[] a) {
//        if (a == null || a.length == 0) {
//            return;
//        }
        int min = a[0];
        int max = a[0];
        for (int i = 1; i < a.length - 1; i++) {
            if (a[i] < min) {
                min = a[i];
            }
            if (a[i] > max) {
                max = a[i];
            }
        }
        int[] ma = {max, min};
        return ma;
    }


    public static int[] cc2() {
        int[] a = new int[10];
        Random random = new Random();
//        int maxs = a[0] ;
        for (int i = 0; i < a.length; i++) {
            a[i] = random.nextInt(10) + 1;
            for (int j = 0; j < i; j++) {
                if (a[i] == a[j]) {
                    i--;
                    break;
                }
            }
        }
        return a;
    }
}

